package rwt.server.util;

import static rwt.server.WebMessages.*;
import rwt.server.RailServer;

public class CoreUtil
{
	/**
	 * If the given string is <tt>null</tt> returns the empty string. Otherwise, the given string is returned.
	 */
	public static String safeString(String str)
	{
		return (str == null ? "" : str);
	}
	
	/**
	 * Returns the extension part of the specified path, without the leading dot.
	 */
	public static String getExtensionWithoutDot(String path)
	{
		int lastDotIndex = path.lastIndexOf('.');
		if (lastDotIndex == -1 || lastDotIndex + 1 >= path.length())
			return "";
		return path.substring(lastDotIndex + 1, path.length());
	}
	
	public static int getSystemStatus()
	{
		if (RailServer.getController().isConnected() && RailServer.getRailroadServer().isConnected())
			return SYSTEM_STATUS_RUNNING;
		return SYSTEM_STATUS_STOPPED;
	}
}
